#ifdef WIN32 //Windows
#include <direct.h>
#include <io.h>
#else  // Linux
#include <sys/io.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#endif

#include <string>
#include <iostream>
#include <gflags/gflags.h>
#include "log/log.h"

DEFINE_string(path, "imag",
                        "采集图片保存目标路径");

int main(int argc, char* argv[]) {
    gflags::SetUsageMessage("cpp中判断并创建路径");
    gflags::ParseCommandLineFlags(&argc, &argv, true);
    
    if (access(FLAGS_path.c_str(), 0) == -1) { //判断该文件夹是否存在
#ifdef WIN32
      int flag = mkdir(FLAGS_path.c_str());  //Windows创建文件夹
#else
      int flag = mkdir(FLAGS_path.c_str(), S_IRWXU);  //Linux创建文件夹
#endif
      if (flag == 0) {  //创建成功
        LOG("Create directory successfully.");
        // int flag = rmdir(FLAGS_path.c_str()); // 删除路径
      } else { //创建失败
        LOG("Fail to create directory.");
        throw std::exception();
      }
    }
    else {
   	    LOG("This directory already exists.");
    }
    return 0;
}